import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './Entitys/User.Enitty';
// 注册实体
const Entitys = TypeOrmModule.forFeature([User]);
@Global()
@Module({
  imports: [
    // 数据库配置
    TypeOrmModule.forRootAsync({
      useFactory() {
        return {
          type: process.env.DB_TYPE as any,
          host: process.env.DB_URL,
          port: process.env.DB_PORT,
          username: process.env.DB_USER,
          password: process.env.DB_PASS,
          database: process.env.DB_DATABASE,
          entities: [User],
          synchronize: true,
        };
      },
    }),
    Entitys,
  ],
  providers: [DbService],
  exports: [DbService, Entitys],
})
export class DbModule {}
